package Ch4;

/**
 * Created by Cai Ye on 2016/3/26.
 */

import java.util.ArrayList;

public class InterfaceClientQueue {
    private ArrayList clients = new ArrayList();
    private ArrayList listeners = new ArrayList();

    public void addInterfaceClientListener(InterfaceClientListener listener) {
        listeners.add(listener);
    }

    public void add(InterfaceClient client) {
        clients.add(client);
        InterfaceClientEvent event = new InterfaceClientEvent(client);
        for (int i = 0; i < listeners.size(); i++) {
            InterfaceClientListener listener = (InterfaceClientListener) listeners.get(i);
            listener.clientAdded(event);
        }
    }

    public void removed(InterfaceClient client) {
        clients.remove(client);
        InterfaceClientEvent event = new InterfaceClientEvent(client);
        for (int i = 0; i < listeners.size(); i++) {
            InterfaceClientListener listener = (InterfaceClientListener) listeners.get(i);
            listener.clientRemoved(event);
        }
    }
}
